<?php


namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Controller;
use App\Services\Admin\RoleService;
use Illuminate\Http\Request;

class RoleController extends Controller
{
    private $roleService;

    public function __construct(RoleService $roleService){
        $this->roleService = $roleService;
    }

    public function getRoleList(Request $request){
        $params = $request->input();
        $result = $this->roleService->getRoleList($params);
        return $result;
    }

    /**
     * 设置管理员状态
     */
    public function setRoleStatus(Request $request){
        $params = $request->input();
        $result = $this->roleService->setRoleStatus($params);
        return $result;
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \Illuminate\Validation\ValidationException
     */
    public function createOrUpdateRole(Request $request){
        $this->validate($request, [
            'role_name' => 'required',
            'role_value' => 'required'
        ]);
        $result = $this->roleService->createOrUpdateRole($request->post());
        return $result;
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function deleteRole(Request $request){
        $result = $this->roleService->deleteRole($request->post('id'));
        return $result;
    }
}
